HTTP request headers and API errors
HTTP request headers
APIs that support specifying HTTP request headers have an optional method argument to pass in header values.
For example, to specify a Stream Transaction ID when creating a document:
await adb.Document.PostDocumentAsync(
"MyCollection",
new MyClass
{
ItemNumber = 123456,
Description = "Some item"
},
new DocumentHeaderProperties()
{
TransactionId = "0123456789"
});
API errors
Any time an endpoint responds with an HTTP status code that is not a “success” code, an ApiErrorException is thrown. You may want to wrap your API calls in a try/catch block and catch ApiErrorException
in certain circumstances.
The ApiErrorException
object contains the ApiError
property, which holds an instance of ApiErrorResponse
with the following structure. ArangoDB has descriptions for the different ErrorNum
values.
/// <summary>
/// ArangoDB API error model
/// </summary>
public class ApiErrorResponse
{
/// <summary>
/// Whether this is an error response (always true).
/// </summary>
public bool Error { get; set; }
/// <summary>
/// Error message.
/// </summary>
public string ErrorMessage { get; set; }
/// <summary>
/// ArangoDB error number.
/// See https://docs.arangodb.com/3.11/develop/error-codes-and-meanings/ for error numbers and descriptions.
/// </summary>
public int ErrorNum { get; set; }
/// <summary>
/// HTTP status code.
/// </summary>
public HttpStatusCode Code { get; set; }
}
Help us improve
Anything unclear or buggy in this tutorial? Provide Feedback